package Text2;

import java.util.*;

public class Main {
    public static HashMap<Integer, Integer> func(List<Pair> list) {
        HashMap<Integer, Integer> map = new HashMap<>();
        if (list.isEmpty()) {
            return map;
        }
        int s = list.get(0).getFirst();
        int flag = s;
        int e = list.get(0).getSecond();
        list.remove(0);
        for (Pair pair : list) {
            if (e < pair.getFirst()) {
               if(s==flag){
                   map.put(s, e);
                   flag= pair.getFirst();
               }
               s= pair.getFirst();
               e= pair.getSecond();
            } else {
                e = Math.max(e, pair.getSecond());
            }
        }
        if (s == flag) {
            map.put(s, e);
        }
        return map;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        List<Pair> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int l = scanner.nextInt();
            int r = scanner.nextInt();
            list.add(new Pair(l, r));
        }
        list.sort(new Cmp());
        System.out.println(func(list).size());
    }
}


class Pair {

    private Integer first;
    private Integer second;


    public Pair(Integer first, Integer second) {
        this.first = first;
        this.second = second;
    }

    public Integer getFirst() {
        return first;
    }

    public Integer getSecond() {
        return second;
    }
}

class Cmp implements Comparator<Pair> {
    @Override
    public int compare(Pair o1, Pair o2) {
        return o1.getFirst() - o2.getFirst();
    }
}


